<?php

if(isset($_POST['dirNameEdit']) && isset($_POST['dirIdParent']) && isset($UID)){
#if it is a dirAdd request

  $dirNameEdit = $_POST['dirNameEdit'];
  $dirIdParent = $_POST['dirIdParent'];

  require_once $BASE_PATH . 'm/dir.php';

  $dircn = new DIR(DBHOST, DBUSER, DBPASS, DBNAME);

  $dircn->add($dirIdParent, $dirNameEdit, $UID);

  $dirParent = $dircn->getById($dirIdParent);

  if($dirParent !== false){

    if($dircn->alt($dirParent['id'], $dirParent['parent'], $dirParent['name'], $dirParent['subdir'] + 1, $dirParent['file'], $dirParent['uid'])){

      require_once $BASE_PATH . 'm/bookmark.php';
      $bmcn = new Bookmark(DBHOST, DBUSER, DBPASS, DBNAME);
      $bookmark = $bmcn->get($UID);

      echo '{"code": 0, "data":' . json_encode($bookmark) . '}';

    }else{
      echo '{"code": 1, "message": "fail to change subdir of parent"}';
    }

  }else{
    echo '{"code": 2, "message": "fail to add dir"}';
  }

}
